package com.neusoft.elm;

import java.util.Scanner;

import com.neusoft.elm.po.Admin;
import com.neusoft.elm.view.AdminView;
import com.neusoft.elm.view.BusinessView;
import com.neusoft.elm.view.impl.AdminViewImpl;
import com.neusoft.elm.view.impl.BusinessViewImpl;

public class ElmAdminEntry {
	
	public void work() {
		Scanner input = new Scanner(System.in);

		System.out.println("=============================================================\n");
		System.out.println("|                   饿了么后台管理系统                        |\n");
		System.out.println("=============================================================\n");

		// 实现登录业务
		AdminView adminView = new AdminViewImpl();
		BusinessView businessView = new BusinessViewImpl();
		Admin admin = adminView.login();
		int chance = 5;
		while(admin == null && chance > 0) {
			System.out.println("管理员名称或密码输入错误，当前机会还有：" + chance-- +" 次。");
			admin=adminView.login();
		}
		
		if(admin != null) {
			System.out.println("\n管理员身份核验完成, 登录成功!");
			int menu = 0;
			while(menu != 5) {
				System.out.println("\n=========1.所有商家列表=2.搜索商家=3.新建商家=4.删除商家=5.退出系统======");
				System.out.println("请输入你的选择：");
				menu = input.nextInt();
				switch(menu) {
				case 1:
					businessView.listBusinessAll();
					break;
				case 2:
					businessView.listBusiness();
					break;
				case 3:
					businessView.saveBusiness();
					break;
				case 4:
					businessView.removeBusiness();
					break;
				case 5:
					System.out.println("欢迎下次光临\n");
					break;
				default:
					System.out.println("没有对应功能\n");
					break;
				}
			}
		}
		else {
			System.out.println("\n管理员名称或密码输入错误次数太多了！\n");
		}

		// 关闭流
		input.close();
	}
	public static void main(String [] args) {
		new ElmAdminEntry().work();
	}
}
